package com.tianhui.consignortwofei.api;

import com.fgs.common.api.CommonOptions;
import com.fgs.common.api.ICommonConfig;
import com.tianhui.consignortwofei.BuildConfig;
import com.tianhui.consignortwofei.constant.AppConfig;
import com.tianhui.consignortwofei.constant.Config;
import com.tianhui.consignortwofei.mvp.ui.activity.MainActivity;

import java.net.Proxy;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

/**
 * @author fgs
 * @date 2020/10/14
 * @description
 **/
public class ApiCommonConfig implements ICommonConfig {
    @Override
    public CommonOptions configOptions() {

        String baseUrl = Config.baseUrl;
        String baseWebUrl = Config.baseWebUrl;
        String baseImageUrl = Config.baseImageUrl;
//        if (BuildConfig.FLAVOR.equals("beta")) {
//            baseUrl = SharedPreferenceManager.getInstance().getBaseUrl();
//            if (!TextUtils.isEmpty(baseUrl)) {
//                Config.baseUrl = baseUrl;
//            } else {
//                baseUrl = Config.baseUrl;
//            }
//            baseWebUrl = SharedPreferenceManager.getInstance().getBaseWebUrl();
//            if (!TextUtils.isEmpty(baseWebUrl)) {
//                Config.baseWebUrl = baseWebUrl;
//            }else {
//                baseWebUrl = Config.baseWebUrl;
//            }
//
//
//            baseImageUrl = SharedPreferenceManager.getInstance().getBaseImageUrl();
//            if (!TextUtils.isEmpty(baseImageUrl)) {
//                Config.baseImageUrl = baseImageUrl;
//            }else {
//                baseImageUrl = Config.baseImageUrl;
//            }
//        }

        return CommonOptions.builder()
                .baseUrl(baseUrl)
                .baseImageUrl(baseImageUrl)
                .baseWebUrl(baseWebUrl)
                .apkUrl(AppConfig.apkUrl)
                .mainClass(MainActivity.class)
                .build();
    }

    @Override
    public Retrofit.Builder retrofit(Retrofit.Builder builder) {
        return builder;
    }

    @Override
    public OkHttpClient.Builder okHttpClient(OkHttpClient.Builder builder) {
        if (!BuildConfig.DEBUG) {
            builder.proxy(Proxy.NO_PROXY);
        }
        return builder.addNetworkInterceptor(new TokenHeaderInterceptor());
    }
}
